home *** CD-ROM | disk | FTP | other *** search
- /*
- Library for ftpd clients.(libftp)
- Copyright by Oleg Orel
- All rights reserved.
-
- This library is desined for free, non-commercial software creation.
- It is changeable and can be improved. The author would greatly appreciate
- any advises, new components and patches of the existing programs.
- Commercial usage is also possible with participation of it's author.
-
-
-
- */
-
- #ifndef __FTPLIBRARY_H
- #define __FTPLIBRARY_H
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/ftp.h>
- #include <netinet/in.h>
- #include <netdb.h>
-
- #ifdef _AIX
- int accept (int, struct sockaddr_in*, int*);
- char *bcopy (char*, char*, size_t);
- int bind (int, const void*, int);
- int connect (int, struct sockaddr_in*, int);
- int gethostname (char*, size_t);
- int getsockname (int, struct sockaddr_in*, int*);
- int getpeername (int, struct sockaddr_in*, int*);
- int getsockopt (int, int, int, void*, int*);
- int listen(int, int);
- int setsockopt (int, int, int, (size_t);
- int socket (int, int, int);
- void free (void*);
- void *malloc (size_t);
- #endif
-
- extern int errno;
-
-
- /* Standard Macros & Definitions */
-
-
-
- #define EXIT(con,e) \
- ( con -> errno = e, \
- ((con->func != NULL) && (e < 0) )?(*(con->func))(con,e,FtpMessage(e)) : 0,\
- ((e==QUIT)&&(con->IO != NULL))?(*(con->IO))(con,errno,strerror(errno)):0,\
- e\
- )
-
- #define MAX_ANSWERS 10 /* Number of known goodest answers for reqest */
- #define QUIT 0
- #define Ctrl(x) ((x) - '@')
- #define FREE(x) memset ( &x , '\0' , sizeof x )
- #define CUT(x) ((x)&0xff)
-
- typedef int STATUS;
- typedef char String[256];
-
-
- /* Common Information Structure */
-
- typedef struct
- {
- int sock;
- FILE *data;
- char mode;
- int errno;
- int ch;
- STATUS (*func)();
- STATUS (*debug)();
- STATUS (*IO)();
- } FTP;
-
- enum {FTP_nodebug,FTP_debug,FTP_noexit};
-
- extern int ftplib_debug;
-
- /* Connect & disconnect */
-
- STATUS FtpConnect(FTP **con,char *hostname);
- #define FtpUser(ftp,user) FtpCommand(ftp,"USER %s",user,230,331,332,EOF)
- #define FtpPassword(ftp,pas) FtpCommand(ftp,"PASS %s",pas,230,332,EOF)
- #define FtpAccount(ftp,acc) FtpCommand(ftp,"ACCT %s",acc,230,EOF)
- STATUS FtpLogin(FTP **con,char *host ,char *user,char *pass,char *acct);
- STATUS FtpBye (FTP * con);
-
- /* Set type of transfer */
-
- #define FtpAscii(ftp) FtpType(ftp,"A")
- #define FtpBinary(ftp) FtpType(ftp,"I")
-
-
- /* Receive Procedures */
-
- STATUS FtpRetrTimeout(FTP *con, char *command,char *inp,char *out,long time);
- #define FtpRetr(ftp,com,inp,out) FtpRetrTimeout(ftp,com,inp,out,0)
- #define FtpGet(ftp,in,out) FtpRetr(ftp,"RETR %s",in,out)
- #define FtpGetTimeout(ftp,in,out,t) FtpRetrTimeout(ftp,"RETR %s",in,out,t)
- #define FtpDirectory(ftp,pat,out) FtpRetr(ftp,"LIST %s",pat,out)
- #define FtpDir(ftp,out) FtpRetr(ftp,"LIST","",out)
-
- /* Send Procedures */
-
- STATUS FtpStorTimeout(FTP *con ,char*command ,char *inp,char *out,long time);
- #define FtpStor(ftp,com,inp,out) FtpStorTimeout(ftp,com,imp,out,0)
- #define FtpPut(ftp,in,out) FtpStor(ftp,"STOR %s",in,out)
- #define FtpPutTimeout(ftp,in,out,t) FtpStorTimeout(ftp,"STOR %s",in,out,t)
-
- /* Command for remote server for startup transfer */
-
- #define FtpGetFile(ftp,file) FtpCommand(ftp,"RETR %s",file,\
- 200,125,150,250,EOF)
- #define FtpPutFile(ftp,file) FtpCommand(ftp,"STOR %s",file,\
- 200,125,150,250,EOF)
-
- /* Command for remote server for startup transfer and make data connection */
-
- STATUS FtpData( FTP * con , char * command , char * param , char *mode);
- STATUS FtpPort ( FTP *con ,int ,int ,int ,int ,int ,int );
- #define FtpOpenRead(ftp,file) FtpData(ftp,"RETR %s",file,"r")
- #define FtpOpenWrite(ftp,file) FtpData(ftp,"STOR %s",file,"w")
- #define FtpOpenAppend(ftp,file) FtpData(ftp,"APPE %s",file,"r")
- STATUS FtpOpenDir( FTP * con , char * files );
- STATUS FtpClose ( FTP *);
-
- /* Command for handing transfer */
-
- STATUS FtpGetString ( FTP * con , char * str );
- STATUS FtpRead ( FTP * con);
- STATUS FtpWrite ( FTP * con , char c);
-
-
- /* Manipulation commands for remote server */
-
- STATUS FtpCommand ();
- #define FtpChdir(ftp,dir) FtpCommand(ftp,"CWD %s",dir,200,250,EOF)
- #define FtpMkdir(ftp,dir) FtpCommand(ftp,"MKD %s",dir,200,257,EOF)
- #define FtpRm(ftp,dir) FtpCommand(ftp,"DELE %s",dir,200,250,EOF)
- char *FtpPwd(FTP *con);
- STATUS FtpMove ( FTP *con,char * old,char *new);
-
- /* Procedures for dialog with remote server */
-
- STATUS FtpInitMessageList();
- STATUS FtpSendMessage( FTP * con , char * Message );
- int FtpGetMessage( FTP * con , char * Message);
- char *FtpMessage(int Number);
- int FtpNumber ( char * Message );
-
-
- /* Debug */
-
- #define FtpSetErrorHandler(con,f) con->func = f
- #define FtpSetDebugHandler(con,f) con->debug = f
- #define FtpSetIOHandler(con,f) con->IO =f
- #define FtplibDebug(t) ftplib_debug=t
- STATUS FtpDebugDebug ( FTP *con, int errno, char * Message);
- STATUS FtpDebugError ( FTP *con, int errno, char * Message);
- STATUS FtpDebugIO ( FTP *con, int errno, char * Message);
- void FtpDebug ( FTP * con );
-
-
- /* Other Procedures */
-
- FILE *FtpFullOpen(char * file,char * mode );
- FILE *Ftpfopen(char *filename,char *mode);
- STATUS FtpFullClose(FILE *);
- STATUS FtpGood ();
- struct hostent *FtpGetHost(char *host);
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #endif /* __FTPLIBRARYH_ */
-
-
-
-